<!<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>第四章</title>
</head>
<body>
    <div id="app" v-if="show">
        <div :class="{ 'active': isActive }"></div>
        <div :class="getClass()"></div>

        <component-a></component-a>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script type="text/javascript">
        Vue.component('component-a',{
            template: '\
                <div> \
                    <div \
                        v-for="(item,index) in navList" \
                        :class="getClass()" \
                        @click="printMsg()"> \
                        点击 \
                    </div> \
                </div>',
            data: function(){
                return {
                    navList: [{},{}]
                }
            },
            methods: {
                getClass:function (){
                    return {
                        'active': true,
                        'error': true
                    }
                },
                printMsg:function(){
                    console.log("点击了");
                }
            }
        })

        var app = new Vue({
            'el': '#app',
            data: {
                isActive: true,
                isError: true,
                show: true
            },
            methods: {
                getClass:function (){
                    return {
                        'active': true,
                        'error': true
                    }
                }
            },
            beforeDestroy() {
                console.log('It will destroy.');
            },
        })
    </script>
</body>
</html>